package com.forenow.demo.demo25;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
 * 1.加载驱动
 * 2.获取连接
 * 3.获取PrepareStatement对象，作用：执行动态SQL语句
 * 4.查询：excuteQuery()  增删改：excuteUpdate()----DML
 * 5.关闭资源
 */
public class JDBCUtil {
    private static String DB_URL= "jdbc:mysql://localhost:3306/test?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC";
    private static String USER= "root";
    private static String PASS= "123456";
    /*
     8.0.X版本的需要在后面加上一串字母变为：
     String url = "jdbc:mysql://local:3306/student?&useSSL=false&serverTimezone=UTC"
     */
    public static void main(String[] args) {
        DBUtil db=new DBUtil();
          try {
              Connection conn = db.GetDB(DB_URL, USER, PASS);
              ResultSet rs = db.Query("select * from emp where id=?", "2");
              if (rs.next()) {
                  System.out.println("ID:"+rs.getInt("EID")+"---"+rs.getString("ENAME"));
              }
              int sql1 = db.update("sql1");
              db.closeAll();
          } catch (SQLException | ClassNotFoundException e) {
                    e.printStackTrace();
          }
     }
}
